package com.zhihaoliang.moshi.list

import androidx.recyclerview.widget.LinearLayoutManager
import com.zhihaoliang.moshi.base.BaseActivity
import com.zhihaoliang.moshi.databinding.ListActivityBinding
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel

/**
 * @author 支豪亮
 * @date 2022/10/31 14:55
 * @des 一个常用的List Activity
 */
abstract class ListActivity : BaseActivity<ListActivityBinding>(), OnListItemClick {

    abstract val listItem: List<ListItem>

    protected val mainScope = MainScope()

    override fun initDataBinding() = ListActivityBinding.inflate(layoutInflater)

    override fun initView() {
        super.initView()

        val linearLayoutManager = LinearLayoutManager(this)
        linearLayoutManager.orientation = LinearLayoutManager.VERTICAL
        dataBinding.rcyList.layoutManager = linearLayoutManager
        dataBinding.rcyList.adapter = ListAdapter(listItem, this)
    }


    override fun onDestroy() {
        super.onDestroy()
        mainScope.cancel()
    }
}